package com.lwj.liwanjia.view.activity.indent;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.view.activity.myindent.MyIndentActivity;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PayCompleteActivity extends BaseActivity {

    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_fangshi)
    TextView tvFangshi;
    @BindView(R.id.tv_xiandan_time)
    TextView tvXiandanTime;
    @BindView(R.id.tv_second)
    TextView tvSecond;
    private int time = 5;
    private Timer timer = new Timer();

    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    time--;
                    tvSecond.setText("" + time);
                    if (time == 0) {
                        Intent intent = new Intent(PayCompleteActivity.this, MyIndentActivity.class);
                        intent.putExtra("type", "-1");
                        startActivity(intent);
                        timer.cancel();
                    }
                }
            });
        }
    };

    @Override
    protected void initView() {
        String type = getIntent().getStringExtra("type");
        if (type.equals("0")) {
            tvFangshi.setText("一卡通支付");
        } else if (type.equals("1")) {
            tvFangshi.setText("支付宝支付");
        }
        tvLeft.setVisibility(View.VISIBLE);
        tvTitle.setText("订单支付成功");
        timer.schedule(task, 1000, 1000);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_pay_complete;
    }


    @OnClick({R.id.tv_left, R.id.tv_wancheng})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_left:
                finish();
                break;
            case R.id.tv_wancheng:
                Intent intent = new Intent(PayCompleteActivity.this, MyIndentActivity.class);
                intent.putExtra("type", "-1");
                startActivity(intent);
                timer.cancel();
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
}
